#include <stdio.h>

#include "interpreter.h"

// 命令行稀疏多项式计算器
// 命令行界面，一次读入一行指令
void Shell()
{
	char ch;
	char command[100] = "";

	printf(">>> ");
	do
	{
		ch = getchar();
		if (ch != '\n')
		{
			strncat(command, &ch, 1);
		}
		else
		{
			if (Interpret(command) == -1)
			{
				printf("error: invalid input\n");
			}
			strcpy(command, "");
			printf(">>> ");
		}
	} while (ch != EOF);

	printf("\nGoodbye\n");
}

int main()
{
	// 将变量 x 添加至变量池
	Poly *poly_x = NewPoly();
	AddNode(poly_x, NewNode(1, 1));
	Var *var_x = NewVar("x", poly_x);

	pool = NewPool();
	PutVar(pool, var_x);

	// 启动命令行界面
	Shell();

	return 0;
}
